package graphBasics.graphRepresentation;

/**
 * 邻接矩阵-稠密图
 * mxf
 */
public class DenseGraph {

    private int n, m; // n为点的个数，m为边的条数
    private boolean directed; // 是否为有向图
    private boolean[][] g; // 具体图的数据

    public DenseGraph(int n, boolean directed) {
        this.n = n;
        this.m = 0; // 初始没有边
        this.directed = directed;
        g = new boolean[n][n];
    }

    public int V(){ return n;} // 返回节点个数
    public int E(){ return m;} // 返回边的个数

    public void addEdge(int v, int w) {
        if(hasEdge(v, w))
            return;
        g[w][v] = true;
        // 无向图需要双向赋值
        if(!directed) {
            g[v][w] = true;
        }
        m++;

    }


    public boolean hasEdge(int v, int w) {
        assert v >= 0 && v < n;
        assert w >= 0 && w < n;

        return g[v][w];
    }

}
